import Toast from './Toast'
let Tst = {}
Tst.install = function (Vue, options) {
  if (document.getElementsByClassName('weui_toast').length) {
    return
  }
  const VueToast = Vue.extend(Toast)
  let $vm = new VueToast({
    el: document.createElement('div')
  })

  let tst = $vm.$mount().$el
  document.body.appendChild(tst)

  Vue.prototype.$showToast = {
    show (options) {
      if (typeof options === 'string') {
        $vm.text = options
      } else if (typeof options === 'object') {
        Object.assign($vm, options)
      }
      $vm.isShow = true
      if ($vm.type === 'success') {
        setTimeout(() => {
          $vm.isShow = false
        }, 2000)
      } else if ($vm.type === 'error') {
        setTimeout(() => {
          $vm.isShow = false
        }, $vm.time)
      } else if ($vm.type === 'violations') {
        // console.log('图片涉及违规，已取消参赛资格')
      } else {
        if ($vm.time > 0) {
          setTimeout(() => {
            $vm.isShow = false
          }, $vm.time)
        } else if ($vm.time === -1) {
          $vm.isShow = false
        }
      }
    },
    hide () {
      $vm.isShow = false
    }
  }
}
export default Tst
